package com.spr.gw.controller.admin;

import com.spr.gw.entity.Message;
import com.spr.gw.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 编辑消息，通过id
     * @param id
     * @param mv
     * @return
     */
    @RequestMapping("/editMessage/{id}")
    public ModelAndView editMessage(@PathVariable("id") Integer id, ModelAndView mv,@RequestParam(required = false) String type){
        Message message = messageService.findOneMessage(id);
        mv.addObject("message", message);
        if(type == null){
            mv.setViewName("admin/page/newsInfo/newsEdit");
        } else {
            mv.setViewName("admin/page/bigimage/imageEdit");
        }
        return mv;
    }
    /**
     * 编辑单页文章消息，通过id
     * @param id
     * @param mv
     * @return
     */
    @RequestMapping("/editArticle/{id}")
    public ModelAndView editArticle(@PathVariable("id") Integer id, ModelAndView mv){
        Message message = messageService.findOneMessage(id);
        mv.addObject("message", message);
        mv.setViewName("admin/page/articleInfo/articleEdit");
        return mv;
    }
    /**
     * 编辑消息，通过类别id，这个消息一个类型只有一条
     * @param id
     * @param mv
     * @return
     */
    @RequestMapping("/editMessageByCategoryId/{categoryId}")
    public ModelAndView editMessageByCategoryId(@PathVariable("categoryId") Integer id, ModelAndView mv){
        Message message = messageService.findOnePageContent(id);
        mv.addObject("message", message);
        mv.setViewName("admin/page/newsInfo/newsEdit");
        return mv;
    }


}
